package com.gko100.action.authority;

import com.gko100.model.User;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

public class UserAuthorityInterceptor extends AbstractInterceptor {

	private static final long serialVersionUID = 4621954022678918701L;

	@Override
	public String intercept(ActionInvocation invocation) throws Exception {
		
		
		ActionContext ctx = ActionContext.getContext();
		
		if(ctx.getSession().get("user")!=null){
			
			User u = (User)ctx.getSession().get("user");
			if(u!=null&&u.getLogState()!=null){
				String logState = u.getLogState();
				if (logState != null && (logState.equals("login")))
				{
					return invocation.invoke();
				}
				else
				{
					return Action.LOGIN;
				}
			}
		}
		
		return Action.LOGIN;
		
	}

}
